Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class DLGpreferences
	Inherits System.Windows.Forms.Form
	
	
	' Form load event ---------------------------------------------------------------------------------------------------------------------------
	
	Public Sub DLGpreferences_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim j As Object
		Dim i As Object
		Dim defaultSearchField As Object
		
		On Error Resume Next
		
		Dim aSplitDefaultExportFields As Object
		
		Dim sDefaultExportFieldsList As String
		
		With New regOp
			
			.Root = regOp.RegRoot.HKEY_LOCAL_MACHINE
			
			.Key = "Software\bbd\AccessSearch\preferences"
			
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			Me.TXTdefaultDatabasePath.Text = .Value("defaultDatabasePath")
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			'UPGRADE_WARNING: Couldn't resolve default property of object defaultSearchField. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			defaultSearchField = .Value("defaultSearchField")
			
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			sDefaultExportFieldsList = .Value("defaultExportFields")
			
			.Key = "Software\bbd\AccessSearch\preferences\remoteDB"
			
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			Me.TXTserverAddress.Text = .Value("serverAddress")
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			Me.TXTupdatePagePath.Text = .Value("updatePagePath")
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			Me.TXTfieldNames.Text = .Value("fieldNames")
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			Me.TXTdatabaseName.Text = .Value("databaseName")
			
		End With
		
		Me.ToolTip1.SetToolTip(Me.TXTdefaultDatabasePath, Me.TXTdefaultDatabasePath.Text)
		
		buildDefaultFieldFieldsList()
		
		For i = 0 To Me.LISTfields.Items.Count - 1
			
			'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			'UPGRADE_WARNING: Couldn't resolve default property of object defaultSearchField. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			If defaultSearchField = VB6.GetItemString(Me.LISTfields, i) Then
				
				'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				Me.LISTfields.SelectedIndex = i
				
				Exit For
				
			End If
			
		Next 
		
		'UPGRADE_WARNING: Couldn't resolve default property of object aSplitDefaultExportFields. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		aSplitDefaultExportFields = Split(sDefaultExportFieldsList, ",")
		
		For i = 0 To Me.LISTdefaultExportFields.Items.Count
			
			For j = 0 To UBound(aSplitDefaultExportFields)
				
				'UPGRADE_WARNING: Couldn't resolve default property of object aSplitDefaultExportFields(j). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				If aSplitDefaultExportFields(j) = VB6.GetItemString(LISTdefaultExportFields, i) Then
					
					LISTdefaultExportFields.SetSelected(i, True)
					
					Exit For
					
				End If
				
			Next 
			
		Next 
		
	End Sub
	
	
	
	Private Sub DLGpreferences_KeyUp(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
		Dim KeyCode As Short = eventArgs.KeyCode
		Dim Shift As Short = eventArgs.KeyData \ &H10000
		
		On Error Resume Next
		
		If KeyCode = 27 Then
			
			Me.Close()
			
		End If
		
	End Sub
	
	
	Private Sub buildDefaultFieldFieldsList()
		Dim i As Object
		
		On Error Resume Next
		
		LISTfields.Items.Clear()
		
		For i = 0 To FRMmain.LISTfields.Items.Count - 1
			
			Me.LISTfields.Items.Add((VB6.GetItemString(FRMmain.LISTfields, i)))
			Me.LISTdefaultExportFields.Items.Add(VB6.GetItemString(FRMmain.LISTfields, i))
			
		Next 
		
	End Sub
	
	Private Function validDefaultSearchField() As Boolean
		Dim i As Object
		
		On Error Resume Next
		
		Dim sDefaultSearchField As String
		
		If Not IsNumeric(Me.LISTfields.SelectedIndex) Or Me.LISTfields.SelectedIndex < 0 Then
			
			Exit Function
			
		End If
		
		sDefaultSearchField = VB6.GetItemString(LISTfields, LISTfields.SelectedIndex)
		
		For i = 0 To FRMmain.LISTfields.Items.Count - 1
			
			If sDefaultSearchField = VB6.GetItemString(FRMmain.LISTfields, i) Then
				
				validDefaultSearchField = True
				
				Exit Function
				
			End If
			
		Next 
		
	End Function
	
	' Events -------------------------------------------------------------------------------------------------------------------------
	
	' OK button click event -----------------------------------------------------------------------------------------------------------------------------------------
	
	Private Sub CMDok_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CMDok.Click
		Dim i As Object
		
		On Error Resume Next
		
		Dim sDefaultSearchField, sDefaultExportFieldsList As String
		
		Dim iConfirm As Object
		
		If Not validDefaultSearchField Then
			
			'UPGRADE_WARNING: Couldn't resolve default property of object iConfirm. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			iConfirm = MsgBox("You have chosen an invalid default search field", MsgBoxStyle.OKCancel)
			
			'UPGRADE_WARNING: Couldn't resolve default property of object iConfirm. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			If iConfirm <> 1 Then Exit Sub
			
		End If
		
		With New regOp
			
			.Root = regOp.RegRoot.HKEY_LOCAL_MACHINE
			.Key = "Software\bbd\AccessSearch\preferences"
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			.Value("defaultDatabasePath") = Me.TXTdefaultDatabasePath.Text
			
			If IsNumeric(Me.LISTfields.SelectedIndex) And Me.LISTfields.SelectedIndex >= 0 Then
				
				sDefaultSearchField = VB6.GetItemString(LISTfields, Me.LISTfields.SelectedIndex)
				
				If sDefaultSearchField = "" Then sDefaultSearchField = "All"
				
				'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				If validDefaultSearchField Then .Value("defaultSearchField") = sDefaultSearchField
				
				For i = 0 To FRMmain.LISTfields.Items.Count - 1
					
					If sDefaultSearchField = VB6.GetItemString(FRMmain.LISTfields, i) Then
						
						'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						FRMmain.LISTfields.SelectedIndex = i
						
						Exit For
						
					End If
					
				Next 
				
			End If
			
			For i = 0 To LISTdefaultExportFields.Items.Count - 1
				
				If LISTdefaultExportFields.GetSelected(i) = True Then
					
					sDefaultExportFieldsList = sDefaultExportFieldsList & VB6.GetItemString(LISTdefaultExportFields, i) & ","
					
				End If
				
			Next 
			
			If Len(sDefaultExportFieldsList) > 0 Then
				
				sDefaultExportFieldsList = VB.Left(sDefaultExportFieldsList, Len(sDefaultExportFieldsList) - 1)
				
				'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				.Value("defaultExportFields") = sDefaultExportFieldsList
				
			End If
			
			.Key = "Software\bbd\AccessSearch\preferences\remoteDB"
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			.Value("serverAddress") = Me.TXTserverAddress.Text
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			.Value("updatePagePath") = Me.TXTupdatePagePath.Text
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			.Value("fieldNames") = Me.TXTfieldNames.Text
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			.Value("databaseName") = Me.TXTdatabaseName.Text
			
		End With
		
		
		Me.Close()
		
	End Sub
	
	' Save the current column widths -------------------------------------------------------------------------------------------------------
	
    Private Sub CMDsaveColumnWidths_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs)

        MODpreferences.saveColumnWidths()

    End Sub
	
	' Browse for choosing the default database -----------------------------------------------------------------------
	
	Private Sub BTNbrowse_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles BTNbrowse.Click
		
		On Error GoTo errorHandler
		
		FRMmain.CommonDialogOpen.ShowDialog()
		
		'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
        With FRMmain.CommonDialogOpen

            If .FileName <> "" Then

                TXTdefaultDatabasePath.Text = .FileName
                ToolTip1.SetToolTip(TXTdefaultDatabasePath, .FileName)

            End If

        End With
		
		buildDefaultFieldFieldsList()
		
errorHandler: 
		
		If Err.Number <> 0 Then
			
			MsgBox(Err.Description & vbCrLf & Err.Number)
			
		End If
		
	End Sub
	
	' Cancel ----------------------------------------------------------------------------------------------
	
	Private Sub CMDcancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CMDcancel.Click
		
		Me.Close()
		
	End Sub
	
	'UPGRADE_WARNING: Event LISTdefaultExportFields.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub LISTdefaultExportFields_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles LISTdefaultExportFields.SelectedIndexChanged
		Dim i As Object
		
		On Error Resume Next
		
		' If 'All' is clicked, then select all of the listItems ----------------------------------------------------------------
		
		If LISTdefaultExportFields.GetSelected(0) = True Then
			
			For i = 1 To LISTdefaultExportFields.Items.Count - 1
				
				LISTdefaultExportFields.SetSelected(i, True)
				
			Next 
			
		End If
		
	End Sub
End Class